<template>
	<view class="container">
		<u-swiper 
			:list="info.imagesUrl" 
			@change="swiperChange" 
			:title="true" 
			mode="round" 
			:autoplay="false"
			:current="current"
			indicator-pos="bottomRight" 
			:circular="false"
			height="450" 
			border-radius="0">
		</u-swiper>
		<scroll-view :scroll-x="true" scroll-with-animation :scroll-left="scrollLeft" class="navtab">
			<view 
				class="navtab_item" 
				:class="current == index ? 'act' : ''"
				@click="navtabClick($event, index)"
				v-for="(item, index) in info.imagesUrl" 
				:key="index">
				<image :src="item.image" mode=""></image>
			</view>
		</scroll-view>
		<view class="news">
			<view class="news_header">
				<text>详情介绍</text>
			</view>
			<view class="news_body">
				<u-parse :html="info.content" :tag-style="style" :show-with-animation="true"></u-parse>
			</view>
		</view>
	</view>
</template>

<script>
	import { baseDetail } from '../../api/api'
	export default {
		data() {
			return {
				current: 0,
				scrollLeft: 0,
				info: {},
				style: {
					image: 'max-width: 100%;',
				}
			};
		},
		onLoad(options) {
			this.getDetail(options.id)
		},
		onReady() {
			this.$u.getRect('.navtab_item').then(res => {
				this.navTabWidth = res.width
			})
			this.$u.getRect('.navtab').then(res => {
				this.contentWidth = res.width -20
			})
		},
		methods: {
			// 获取详情
			getDetail(id) {
				baseDetail({ id }).then(res => {
					if (res.code == 1) {
						this.info = res.data
					} else {
						this.$u.toast(res.msg)
					}
				})
			},
			swiperChange(index) {
				// if (index == 0) this.scrollLeft = 0
				this.current = index
				this.$u.getRect('.navtab_item').then(res => {
					this.scrollLeft = res.width*index - (res.width-8)*2
				})
				
			},
			navtabClick(e, index) {
				this.current = index
			}
		}
	}
</script>

<style lang="scss">
	page {
		// background-color: #fff;
	}

	.navtab {
		display: flex;
		height: 150rpx;
		padding: 20rpx;
		background-color: #fff;
		white-space: nowrap;
		box-sizing: border-box;

		.navtab_item {
			position: relative;
			display: inline-block;
			width: 130rpx;
			height: 110rpx;
			margin-right: 20rpx;
			
			&:last-child {
				margin-right: 0;
			}
			image {
				position: absolute;
				bottom: 0;
				width: 100%;
				height: 96rpx;
				border-radius: 8rpx;
				transition: height linear 0.3s;
			}
		}
		.act {
			image {
				height: 110rpx;
			}
		}

	}
	/deep/ .uni-scroll-view-content {
		height: 96rpx;
	}

	.news {
		width: 100%;
		background-color: #fff;
		margin-top: 15rpx;

		.news_header {
			display: flex;
			align-items: center;
			justify-content: space-between;
			width: 100%;
			padding: 30rpx 25rpx;
			border-bottom: 1px solid #eee;

			text {
				position: relative;
				font-size: 32rpx;
				font-weight: 700;
				padding-left: 30rpx;

				&::before {
					content: '';
					position: absolute;
					top: 0;
					left: 0;
					width: 8rpx;
					height: 100%;
					border-radius: 4rpx;
					background-color: #4CD964;
				}
			}
		}

		.news_body {
			width: 100%;
			padding: 25rpx;
			text-align: justify;
		}
	}
</style>
